<#include "./template/general_temp.ftl">

<#macro content>
<div class="row">
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <h2><i class="glyphicon glyphicon-author"></i>专栏作者</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content">
                <form class="form-inline" role="form">
                    <div class="form-group">
                        <label class="sr-only" for="name">姓名</label>
                        <input type="text" class="form-control" id="name" placeholder="请输入要查询的用户名">
                    </div>
                    <button type="button" onclick="queryData()" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
                </form>
                <table id="author_dg">
                </table>
            </div>
        </div>
    </div>
    <!--/span-->

</div><!--/row-->
</#macro>

<#macro script>
<script type="text/javascript">
    function getQueryCondition(){
        var name = $("#name").val();
        return {"name":name};
    }
    function queryData(){
        var pars=getQueryCondition();
        //构造列表
        jQuery('#author_dg').datagrid({
            url:'${base}/system/author/list',
            fitColumns : true,
            striped : true,
            pagination : true,
            rownumbers : true,
            pageSize : 50,
            pageNumber : 1,
            pageList : [ 50, 100, 150, 200, 250],
            loadMsg : '数据正在加载中...',
            singleSelect:true,
            queryParams : pars,
            selectOnCheck : false,
            checkOnSelect : false,
            width:$('.box-content').width() * 0.985,
            columns : [[
                {field : 'username', title : '用户名',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center'},
                {field : 'nickName', title : '昵称',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.1, align: 'center'},
                {field : 'postCount', title : '发文数',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center'},
                {field : 'statusName', title : '状态',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center'},
                {field : 'isHot', title : '热门魔客',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center',
                    formatter:function(value,row,index){
                        var selectedBlk = "selected='selected'";
                        var select = "<select style='cursor:pointer;background:#0081c2;color:#FFFFFF;' onchange='changeHot(this," + row.id+")'>";
                                select +="<option value='1'";
                                if(row.extra1 == 1){
                                    select += selectedBlk;
                                }
                                select += ">是</option><option value='0'";
                                if(row.extra1 == 0){
                                    select += selectedBlk;
                                }
                                select += " >否</option></select>";
                        return select;
                    }
                },
                {field : 'ctrl', title : '变更角色',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center',
                    formatter:function(value,row,index){
                        var select = "<select style='cursor:pointer;background:#0081c2;color:#FFFFFF;' onchange='changeRole(this," + row.id+")'>" +
                                "<option value='1'>普通用户</option><option value='3' selected='selected'>专栏作者</option></select>";

                        return select;
                    }
                }
            ]],
            onLoadSuccess:function(data){
            },
            onClickRow: function (rowIndex, rowData) {

            }
        });
    }

    function changeRole(obj,id){
        if(window.confirm("确认变更该用户角色？")){
            jQuery.ajax({
                type: "POST",
                url: '${base}/system/author/changeRole',
                dataType:"json",
                data: {"id": id},
                success: function(data){
                    if(data.status == 1) {
                        alert("变更成功！");
                        queryData();
                    }else{
                        alert("变更失败！");
                    }
                },
                error: function (obj){
                    console.info(obj);
                }
            });
        }
    }

    function changeHot(obj,id){
        if(window.confirm("是否变更热门魔客？")){
            jQuery.ajax({
                type: "POST",
                url: '${base}/system/author/changeHot',
                dataType:"json",
                data: {"id": id},
                success: function(data){
                    if(data.status == 1) {
                        alert("变更成功！");
                        queryData();
                    }else{
                        alert("变更失败！");
                    }
                },
                error: function (obj){
                    console.info(obj);
                }
            });
        }
    }

    $(document).ready(function () {
        queryData();
    });

    function edit(id){
        window.location = "${base}/system/author/edit?id=" + id;
    }
    function del(id){
        if(window.confirm("确认删除？")) {
            jQuery.ajax({
                type: "POST",
                url: '${base}/system/author/delete',
                dataType:"json",
                data: {"id": id},
                success: function(data){
                    if(data.status == 1) {
                        alert("删除成功！");
                        reQueryData();
                    }
                },
                error: function (obj){
                    console.info(obj);
                }
            });
        }
    }
</script>
</#macro>
